package br.mikhas.container.factory;

import br.mikhas.container.config.BeanDefinition;

/**
 * <p>
 * Describes the interface of a container bean factory.
 * 
 * <p>
 * The Beanfactory is responsible for the creation, configuration and
 * destruction of the beans across the registered scopes
 * 
 * @author Mikhail Domanoski
 * 
 */
public interface BeanFactory {

	/**
	 * Register the scope with its name
	 * 
	 * @param scope
	 *            The implementation of the scope
	 */
	public void registerScope(Scope scope);

	/**
	 * Gets and resource from one of the registered scopes or creates it if the
	 * ResourceDefinition is registered
	 * 
	 * @param name
	 *            The name of the resource to be provided
	 */
	public Object getResource(String name);

	/**
	 * Gets and resource from one of the registered scopes or creates it if the
	 * ResourceDefinition is registered
	 * 
	 * @param name
	 *            The name of the resource to be provided
	 * 
	 * @param type
	 *            The type of the resource
	 */
	public <T> T getResource(String name, Class<T> type);

	/**
	 * Gets a resource from one of the registered scopes or creates it if the
	 * ResourceDefinition is registered
	 * 
	 * @param type
	 *            The type of the resource
	 */
	public <T> T getResource(Class<T> type);

	/**
	 * Gets all resources from one of the registered scopes or creates it if the
	 * ResourceDefinition is registered
	 * 
	 * @param type
	 *            The type of the resources
	 */
	public <T> T[] getResources(Class<T> type);

	/**
	 * Initializes the named scope instantiating and wiring the beans on it
	 * 
	 * @param scopeName
	 */
	public void initializeScope(String scopeName);

	/**
	 * Destroy the named scope and finalizes all managed resources
	 */
	public void destroyScope(String scopeName);

	/**
	 * Checks if a named scope is ainitialized on this bean factory
	 * 
	 * @param scopeName
	 *            The name of the scope to check
	 * @return <code>true</code> if the scope is initialized.
	 */
	public boolean isScopeInitialized(String scopeName);

	/**
	 * Register a resource to the {@link BeanFactory} to manage it.
	 */
	public void registerDefinition(BeanDefinition definition);

	/**
	 * Checks if the named scope is registered on the factory.
	 * 
	 * @param scope
	 *            The name of the scope
	 * @return
	 */
	public boolean containsScope(String scope);
}
